﻿using DTO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using DAO;

namespace BUS
{
    public class ChiTietBCCongNo_BUS
    {
        private static ChiTietBCCongNo_BUS m_instance = null;

        public static ChiTietBCCongNo_BUS Instance
        {
            get
            {
                if (m_instance == null)
                    m_instance = new ChiTietBCCongNo_BUS();
                return m_instance;
            }
        }

        /// <summary>
        ///   lay thong tin no
        /// </summary>
        /// 
        public List<ChiTietBCCongNo_DTO> LayThongTinNo(BaoCaoCongNo_DTO _item)
        {
            List<ChiTietBCCongNo_DTO> result = new List<ChiTietBCCongNo_DTO>();

            DataTable dt = ChiTietBCCongNo_DAO.Instance.LayPhieuBanHang(_item.NgayBaoCao);
            DataRowCollection list = dt.Rows;
            if (list.Count == 0)
            {
                return null;
            }
            for (int i = 0; i < list.Count; i++)
            {
                DataRow dr = list[i];
                string _id = (string)dr["MaPhieuBanHang"];
                DataTable _temp = ChiTietBCCongNo_DAO.Instance.LayThongTinNo(_id);
                DataRowCollection _templist = _temp.Rows;
                if (_templist.Count==0)
                {
                    return null;
                }
                for (int j = 0; j < _templist.Count; j++)
                {
                    DataRow _dr = _templist[j];
                    string _maphieuno = (string)_dr["MaPhieuNo"];
                    decimal _tien = (decimal)_dr["ConLai"];
                    long _tienNo = (long)_tien;
                    ChiTietBCCongNo_DTO item = new ChiTietBCCongNo_DTO("", _item.MaBaoCao, _maphieuno, _tienNo);
                    result.Add(item);
                }
            }
            return result;
        }

        /// <summary>
        ///   
        /// them ct bao cao cong no
        /// </summary>
        /// 
        public bool ThemThongTin(ChiTietBCCongNo_DTO _item)
        {
            return ChiTietBCCongNo_DAO.Instance.ThemThongTin(_item.MaBaoCao, _item.MaPhieuNo, _item.TienNo);
        }
    }
}
